<template>
  <div class="back-btn" @click="goBack()">
    <i class="iconfont icon-back"></i>
    <span class="text">返回</span>
  </div>
</template>
<script>
export default {
  name: 'c-back-btn',
  props: {
    to: {
      type: Object,
      default: () => {
        return null
      }
    }
  },
  methods: {
    goBack () {
      if (this.to) {
        this.$router.push(this.to)
      } else {
        window.history.length > 2 ? this.$router.go(-1) : this.$router.push('/')
      }
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.back-btn {
  display: inline-block;
  width: 76px;
  height: 26px;
  line-height: 26px;
  cursor: pointer;
  background: #FFFFFF;
  border: 1px solid #DCDFE6;
  color: #606266;
  text-align: center;
  font-size: 14px;
  border-radius: 4px;
  margin-left: 8px;
  &:hover {
    color: #409EFF;
    background: #ecf5ff;
    border-color: #b3d8ff;
  }
  .icon-back {
    font-size: 14px;
  }
}
</style>
